package com.shengyijie.context; 

import java.io.File;

import org.apache.http.HttpResponse;

import com.shengyijie.model.http.HttpConnectApi;
import com.shengyijie.model.json.JsonParser;
 
 

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;

public class Commen {

	public static void userKey( final Context context){
		
		new Thread() {
            @Override
            public void run() {
            	try {
            		HttpConnectApi httpConnect=HttpConnectApi.getInstance();
                    HttpResponse response=httpConnect.userKey(context); 
                    if (response.getStatusLine().getStatusCode() == 200)
        			{ 
                   	    JsonParser jsonParser=JsonParser.getInstance();
                   	    jsonParser.getResultCode(response) ;
                   	    	 
                   	    
        			}
                }catch (Exception e) {} 
            }
        }.start(); 
     } 
	
public static void setGuestBook( final String sessionID, final String id ){
		
		new Thread() {
            @Override
            public void run() {
            	try {
            		HttpConnectApi httpConnect=HttpConnectApi.getInstance();
                    HttpResponse response=httpConnect.setGuseBook(sessionID, id); 
//                    if (response.getStatusLine().getStatusCode() == 200)
//        			{ 
//                   	    JsonParser jsonParser=JsonParser.getInstance();
//                   	    jsonParser.getResultCode(response) ;
//                   	    	 
//                   	    
//        			}
                }catch (Exception e) {} 
            }
        }.start(); 
     } 
	
	
	public static void deleteAllImageCache(){		
		try { 
			if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {   
				 File destDir = new File(Environment.getExternalStorageDirectory(),"diipo");
				  if (destDir.exists()) {
					    String[] children = destDir.list();
					    if(children.length>300)
					        for (int i = 0; i < children.length; i++) 
					        {
					           File temp =  new File(destDir, children[i]);
					           temp.delete();
					        }
				  } 
			}  
		} catch (Exception e) {}
	}
	
	public static void map(Context context,double lat,double lng){
		try{  
		    Intent i = new Intent(  
	        Intent.ACTION_VIEW, Uri.parse("http://ditu.google.cn/maps?hl=zh&mrt=loc&q="+lat+
	    		","+lng));  
		    context.startActivity(i); 
		}catch(Exception e){}
   }
	
	 public static void call(Context context,String number) {
	 		try {
	 			Uri uri = Uri.parse("tel:" + number );
	 			Intent it = new Intent(Intent.ACTION_VIEW, uri);
	 			context.startActivity(it);
	 		} catch (Exception e) {}
	 	}
	 
	 
}
